package com.hl.sfzy.service.course;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.entity.course.Course;
import com.hl.sfzy.mapper.course.CourseMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.*;

/**
 * @program: sfzy
 * @description: 课程主页面
 * @author: xiaoyan
 * @create: 2024-09-05 14:39
 **/

@Service
public class CourseAllService {

    @Autowired
    private CourseMapper courseMapper;

    public PageInfo<Course> courseAllContent(Integer page, Integer size) {
        PageHelper.startPage(page, size);
        List list = courseMapper.courseAllContent();
        PageInfo<Course> pageInfo = new PageInfo<>(list);

        return pageInfo;
    }

    //根据id查询
    public Course courseAllContentById(Long id) {
        return courseMapper.selectByPrimaryKey(id);
    }

    //新增课程
    public int courseInsert(Course course) {
        return courseMapper.insertSelective(course);
    }

    //删除课程
    public int courseDelete(Long id) {
        return courseMapper.deleteByPrimaryKey(id);
    }

    //修改课程
    public int updateCourse(Course course) {
        return courseMapper.updateByPrimaryKeySelective(course);
    }

    //模糊搜索
    public PageInfo<Course> courseLikeSearch(Integer page, Integer size, Date startTime, Date endTime, String name) {
        PageHelper.startPage(page, size);
        List list = courseMapper.courseLikeSearch(name, startTime, endTime);
        PageInfo<Course> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }


}
